var Answer_confirm_error = "Xác nhận trả lời phải giống trả lời.";
function show_hide_password(){
	var sAnswer_old = $('#sAnswer').val();
	var flag = $('#sAnswer_confirm_tr').css("display");
	var sAnswer_text = '<INPUT class="txt_260" id="sAnswer" onFocus="onFocus(this)" maxLength="100" name="sAnswer" type="text" tabindex="0" onblur="onBlurAnserRegister();" value="'+sAnswer_old+'" onChange="onChangeAnser1();">';
	var sAnswer_pass = '<INPUT class="txt_260" id="sAnswer" onFocus="onFocus(this)" maxLength="100" name="sAnswer" type="password" tabindex="0" onblur="onBlurAnserRegister();">';	
	if(flag == 'none'){
		$('#sAnswer_confirm_tr').show();
		$("#sAnswer_update").html(sAnswer_pass);
		$("#sAnswer").focus();
		$('#answer_opt').html('Hiện chữ');
	}else{
		$('#sAnswer_confirm_tr').hide();
		$("#sAnswer_update").html(sAnswer_text);
		$("#sAnswer").focus();
		$('#answer_opt').html('Ẩn chữ');
	}
	$('#sAnswer_confirm').val('');
	hideError("#sAnswer_confirm");	
	$("#sAnswer").focus();
}
function onChangeAnser1(){
	$("#sAnswer_confirm").val('');
	hideError("#sAnswer_confirm");
}
function onBlurAnserRegister(){
	hideError("#sAnswer");
	var sAnswer = $('#sAnswer').val();	
	if(sAnswer != ''){		
		checkValid("#sAnswer_icon");
	}else{
		$("#sAnswer_confirm").val('');
		hideError("#sAnswer_confirm");
	}
	$("#sAnswer_note").hide();	
}
function onKeyUpConfirmAnswer(obj){	
	var sAnswer = $('#sAnswer').val();
	var sAnswer_confirm = obj.value;
	var flag = false;	
	if(sAnswer_confirm.length < sAnswer.length || sAnswer == ''){	
		//hideError("#sAnswer_confirm");
		return false;
	}	
	if(sAnswer_confirm.length == sAnswer.length){
		if(sAnswer == obj.value){
			checkValid("#sAnswer_confirm_icon");
			flag = true;
		}
	}
	if(flag){				
		hideError("#sAnswer_confirm");
	}else{
		$("#sAnswer_confirm_icon").hide();
		showError('#sAnswer_confirm',Answer_confirm_error);
	}
	return true;
}
function onBlurConfirmAnswer(obj){	
	var sAnswer = $('#sAnswer').val();
	var sAnswer_confirm = obj.value;
	if(sAnswer == ''){
		$('#sAnswer_confirm').val('');
		hideError("#sAnswer_confirm");
	}
	if(sAnswer == '' && sAnswer_confirm == ''){
		hideError("#sAnswer_confirm");
		return false;
	}	
	if(sAnswer != '' && sAnswer_confirm == ''){
		showError('#sAnswer_confirm',Require_Error);
		return false;
	}
	if(sAnswer == obj.value){
		hideError("#sAnswer_confirm");
	}else{
		showError('#sAnswer_confirm',Answer_confirm_error);
	}
	return true;
}
function checkSubmitConfirmAnswer(){
	hideNote('sAnswer');
	var flag = $('#sAnswer_confirm_tr').css("display");
	var sAnswer = $('#sAnswer').val();	
	var sAnswer_confirm = $('#sAnswer_confirm').val();		
	if(flag != 'none'){
		if(sAnswer != ''){
			if(sAnswer_confirm == ''){
				showError('#sAnswer_confirm',Require_Error);
				return false;
			}
			if(sAnswer_confirm != sAnswer){
				showError('#sAnswer_confirm',Answer_confirm_error);
				return false;				
			}			
		}
	}
	return true;
}
// dung cho cac form change Q&A, Update Account
function show_hide_password1(){
	var sAnswer_old = $('#answer').val();
	var flag = $('#answer_confirm_tr').css("display");
	var answer_text = '<INPUT class="txt_260" id="answer" maxLength="100" name="answer" type="text" tabindex="1" onFocus="onfocusAnswer()"  onblur="onBlurAnser();"value="'+sAnswer_old+'" onChange="onChangeAnser();" >';
	var answer_pass = '<INPUT class="txt_260" id="answer" maxLength="100" name="answer" type="password" tabindex="1" onFocus="onfocusAnswer()" onblur="onBlurAnser();">';	
	if(flag == 'none'){
		$('#answer_confirm_tr').show();
		$("#answer_update").html(answer_pass);
		$("#answer").focus();
		$('#answer_opt').html('Hiện chữ');
	}else{
		$('#answer_confirm_tr').hide();
		$("#answer_update").html(answer_text);
		$("#answer").focus();
		$('#answer_opt').html('Ẩn chữ');
	}
	$('#answer_confirm').val('');
	hideError("#answer_confirm");
	$("#answer").focus();	
}
function onfocusAnswer(){
	var answer = $('#answer').val();
	if(answer == ''){
		hideError("#answer");				
		$("#answer_tr_note").addClass("td_note");
		$("#answer_note").show();
		$('#answer_confirm').val('');
		hideError("#answer_confirm");
	}else{
		onBlurAnser();
	}
}
function onBlurAnser(){
	hideError("#answer");
	var answer = $('#answer').val();	
	if(answer != ''){
		checkValid("#answer_icon");
	}else{
		hideError("#answer_confirm");
	}
	$("#answer_note").hide();		
}
function onKeyUpConfirmAnswer1(obj){	
	var answer = $('#answer').val();
	var answer_confirm = obj.value;
	var flag = false;	
	if(answer_confirm.length < answer.length || answer == ''){	
		//hideError("#answer_confirm");
		return false;
	}	
	if(answer_confirm.length == answer.length){
		if(answer == obj.value){
			checkValid("#answer_confirm_icon");
			flag = true;
		}
	}
	if(flag){				
		hideError("#answer_confirm");
	}else{
		$("#answer_confirm_icon").hide();
		showError('#answer_confirm',Answer_confirm_error);
	}
	return true;
}
function onBlurConfirmAnswer1(obj){	
	var answer = $('#answer').val();
	var answer_confirm = obj.value;
	if(answer == '' && answer_confirm == ''){
		hideError("#answer_confirm");
		return false;
	}	
	if(answer != '' && answer_confirm == ''){
		showError('#answer_confirm',Require_Error);
		return false;
	}
	if(answer == obj.value){
		hideError("#answer_confirm");
	}else{
		showError('#answer_confirm',Answer_confirm_error);
	}
	return true;
}
function checkSubmitConfirmAnswer1(){
	var flag = $('#answer_confirm_tr').css("display");
	var answer = $('#answer').val();	
	var answer_confirm = $('#answer_confirm').val();		
	if(flag != 'none'){		
		if(answer_confirm == ''){
			showError('#answer_confirm',Require_Error);
			return false;
		}
		if(answer_confirm != answer){
			showError('#answer_confirm',Answer_confirm_error);
			return false;				
		}			
	}
	return true;
}
// dung cho cac form change Forgot
function show_hide_password2(){
	var sAnswer_old = $('#answer').val();
	var answer_text = '<INPUT class="txt_260" id="answer" maxLength="100" name="answer" type="text" tabindex="1" onblur="onBlurAnser();" value="'+sAnswer_old+'" onChange="onChangeAnser();">';
	var answer_pass = '<INPUT class="txt_260" id="answer" maxLength="100" name="answer" type="password" tabindex="1" onblur="onBlurAnser();">';
	var flag = $('#answer_opt').html();
	if(flag == 'Ẩn chữ'){
		$("#answer_update").html(answer_pass);
		$("#answer").focus();
		$('#answer_opt').html('Hiện chữ');
	}else{
		$("#answer_update").html(answer_text);
		$("#answer").focus();
		$('#answer_opt').html('Ẩn chữ');
	}
	$("#answer").focus();	
}
function onChangeAnser(){
	$("#answer_confirm").val('');
	hideError("#answer_confirm");
}
////////
$("#question").focus( function() {	
	var is_forgot = $('#forgotpass_qna').val();
	if(is_forgot == 'forgotpass_qna'){
		hideError("#question");
		return false;	
	}
	if(this.value == -1){
		hideError("#question");
		//$('#answer').val('');
		//$('#answer_confirm').val('');
		$("#question_tr_note").addClass("td_note");
		$("#question_note").show();
		hideError("#answer_confirm");
		hideError("#answer");
		
		//$("#answer").val('');
		//$("#answer_confirm").val('');	
		hideError('#sAnswer');
		hideError('#sAnswer_confirm');
	}
} );
$("#question").change( function() {	
	$("#sAnswer").val('');
	$("#sAnswer_confirm").val('');	
	hideError('#sAnswer');
	hideError('#sAnswer_confirm');
	
	$("#answer").val('');
	$("#answer_confirm").val('');	
	hideError('#answer');
	hideError('#answer_confirm');
} );
$("#question").blur( function(){
    $('#question_note').hide();
	$("#question_tr_note").removeClass("td_note");
	if($("#question").val()!=-1) {
		checkValid("#question_icon");
	}
} );